﻿using BLL;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace WeChat
{
    public partial class SubmitOrderReturn : System.Web.UI.Page
    {   //密钥
	string publickey = "";
	//操作员
	string num = "";
	//提交支付
	protected void Page_Load(object sender, EventArgs e)
	{
	    Secretkey();
	    Operator();
	    string business_no = "1001100024";
	    string tn = "0001";
	    string userID = num;
	    //金额
	    string price = Request["price"].ToString();
	    //地址
	    string address = Request["address"].ToString();
	    //手机
	    string telnum = Request["telnum"].ToString();
	    //String publickey = publickey;
	    //String q = (this.comboBox1.SelectedIndex + 1).ToString();
	    //if (q == "0") { MessageBox.Show("请选择支付类型"); return; }
	    string q = Request["bmmc"].ToString();
	    //此处自行验证各值合法性
	    string urldz = "http://498.jocat.com/RetCallback.aspx";
	    string json = "{\"a\":\"payCode\",\"i\":\"" + userID + "\",\"j\":\"" + price + "\",\"q\":\"" + q + "\",\"tn\":\"" + tn + "\",\"t\":\"3\",\"z\":\"2\",\"notify_url\":\"" + urldz + "?Types=" + "Paymentconsumption" + " & opId=" + Session["openid"] + "+&money= " + price + "&q=" + q + "&business_no=" + business_no + "&tn=" + tn + "&address="+ address+ "&telnum="+ telnum + "\"}";
	    string returnTxt = RsaDemo.Common.HttpPost("s=" + RsaDemo.Common.rsaEncode(publickey, json, business_no));
	    IDictionary<string, object> rlt = RsaDemo.Common.JsonToDictionary(returnTxt);
	    if (rlt["f"].ToString() == "2")
	    {
		IDictionary<string, object> d = (IDictionary<string, object>)rlt["d"];
		//this.textBox8.Text = d["qr"].ToString();
		Session["IsValue"] = d["qr"].ToString();
		Session["q"] = q;
		Session["o"] = d["o"].ToString();
		Session["business_no"] = business_no;
		Session["tn"] = tn;
		string o = Context.Session["o"].ToString();
		string openid = Context.Session["openid"].ToString();
		string rfkh = ReBLL.SelectRfkh(openid);
		DateTime dateTimes = DateTime.Now;
		//ReBLL.OrderNum(o, Convert.ToDouble(price), rfkh, dateTimes);


		//跳支付页面
		if (q != "1")
		{
		    Response.Redirect("http://498.jocat.com/Paymentpage.aspx");
		    //  Response.Redirect("http://localhost:3027/Paymentpage.aspx");
		}
		else
		{

		    Response.Redirect(d["qr"].ToString());
		}

	    }
	    else
	    {
		Context.Response.Write("<script>alert('请选择支付类型！')</script>");
	    }
	}



	//获取密钥
	public void Secretkey()
	{
	    string business_no = "1001100024";
	    string sn = "23:ef:ee:29:32:34";
	    //此处自行验证各值合法性
	    string json = "{\"a\":\"getKey\",\"e\":\"" + business_no + "\",\"sn\":\"" + sn + "\"}";
	    string returnTxt = RsaDemo.Common.HttpPost("json=" + json);
	    IDictionary<string, object> rlt = RsaDemo.Common.JsonToDictionary(returnTxt);
	    if (rlt["f"].ToString() == "1")
	    {
		IDictionary<string, object> d = (IDictionary<string, object>)rlt["d"];
		//this.richTextBox1.Text = d["k"].ToString();
		publickey = d["k"].ToString();
		//this.textBox5.Text = "0001";
	    }
	    else
	    {
		//MessageBox.Show(rlt["m"].ToString());
	    }
	}
	//操作员
	public void Operator()
	{
	    string business_no = "1001100024";
	    string user = "1001100024";
	    string pwd = "123456";
	    string tn = "0001";
	    //此处自行验证各值合法性
	    string json = "{\"a\":\"login\",\"ou\":\"" + user + "\",\"op\":\"" + pwd + "\",\"tn\":\"" + tn + "\"}";
	    string returnTxt = RsaDemo.Common.HttpPost("s=" + RsaDemo.Common.rsaEncode(publickey, json, business_no));
	    IDictionary<string, object> rlt = RsaDemo.Common.JsonToDictionary(returnTxt);
	    if (rlt["f"].ToString() == "1")
	    {
		IDictionary<string, object> d = (IDictionary<string, object>)rlt["d"];
		//this.textBox6.Text = d["i"].ToString();
		num = d["i"].ToString();
	    }
	    else
	    {
		//MessageBox.Show(rlt["m"].ToString());

	    }
	}
    }
}